package dal

import (
	. "7qule.com/sd3/CrossServer/src/bll/challenge/model"
	baseDal "7qule.com/sd3/CrossServer/src/dal"
)

// 擂台排行榜长度Model访问结构
type baseChallengeLeaderboardLenModelDal struct{}

// 访问结构对象
var BaseChallengeLeaderboardLenModelDal = new(baseChallengeLeaderboardLenModelDal)

// 初始化
func init() {
	// 注册到同步对象中
	baseDal.GetSyncMgr().RegisterSyncObj(BaseChallengeLeaderboardLenModelDal.TableName())
}

// TableName 表名
func (this *baseChallengeLeaderboardLenModelDal) TableName() string {
	return "b_challenge_leaderboardlen"
}

// GetData 从数据库获取配置数据
// dataContainer:擂台排行榜长度对象
// 返回值:
// interface{}:获取到的数据
// error:错误信息
func (this *baseChallengeLeaderboardLenModelDal) GetData() ([]*BaseChallengeLeaderboardLenModel, error) {
	sql := "SELECT `LeaderboardLen` FROM `b_challenge_leaderboardlen`;"

	db := baseDal.GetGameDB().DB()
	execResult, err := db.Query(sql)
	if err != nil {
		baseDal.WriteLog("BaseChallengeLeaderboardLenModelDal", err)

		return nil, err
	}

	defer execResult.Close()

	// 读取数据
	var result = make([]*BaseChallengeLeaderboardLenModel, 0, 16)
	for execResult.Next() {
		var tempNewItem = NewBaseChallengeLeaderboardLen()
		err = execResult.Scan(
			&tempNewItem.LeaderboardLen)

		if err != nil {
			baseDal.WriteLog("BaseChallengeLeaderboardLenModelDal", err)
			return nil, err
		}

		result = append(result, tempNewItem)
	}
	return result, nil
}
